package com.zhz.system.repository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhz.common.tool.mybatisplus.base.dal.repository.impl.BaseRepositoryImpl;
import com.zhz.model.system.Permission;
import com.zhz.model.system.contract.dto.PermissionDTO;
import com.zhz.model.system.contract.param.PermissionQueryParam;
import com.zhz.system.repository.dao.PermissionDao;
import com.zhz.system.repository.service.PermissionService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 权限服务实现
 *
 * @author zhouhengzhe
 * @date 2023/3/30
 */
@Service
public class PermissionServiceImpl extends BaseRepositoryImpl<PermissionDao, PermissionDTO, Permission, PermissionQueryParam> implements PermissionService {
    @Override
    protected QueryWrapper<Permission> getWrapper(PermissionQueryParam queryParam) {
        return new QueryWrapper<Permission>()
                .eq(Objects.nonNull(queryParam.getId()), Permission.ID, queryParam.getId())
                .in(Objects.nonNull(queryParam.getIdSet()), Permission.ID, queryParam.getIdSet())
                .eq(Objects.nonNull(queryParam.getPid()), Permission.PID, queryParam.getPid())
                .in(CollectionUtils.isNotEmpty(queryParam.getPidSet()), Permission.PID, queryParam.getPidSet())
                .eq(Objects.nonNull(queryParam.getEnVisible()), Permission.EN_VISIBLE, queryParam.getEnVisible())
                .eq(Objects.nonNull(queryParam.getType()), Permission.TYPE, queryParam.getType())
                .in(CollectionUtils.isNotEmpty(queryParam.getTypeSet()), Permission.TYPE, queryParam.getTypeSet());
    }
}
